from django_redis import get_redis_connection

# 访问redis
class MyRedis:
    def __init__(self):
        self.conn = get_redis_connection('default')

    # 设置一个值
    def setstr(self,key,value):
        self.conn.set(key,value)

    # 设置一个有效期的值
    def setex(self,key,value,ex):
        self.conn.setex(key,ex,value)
    #   删除
    def delstr(self,key):
        self.conn.delete(key)
    # 获取值
    def getstr(self,key):
        val=self.conn.get(key)
        if val:
            return val.decode("utf-8")
        else:
            return None

rediss=MyRedis()